
//
//  HDBottomView.swift
//  HDSwfitWeibo
//
//  Created by wty on 16/4/13.
//  Copyright © 2016年 wty. All rights reserved.
//

import UIKit

class HDBottomView: UIView {

 //MARK   初始化方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.whiteColor()
        //创建子控件和添加约束
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    private func prepareUI(){
        //创建子控件
        addSubview(forwordBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
        addSubview(lineOne)
        addSubview(lineTwo)
        
        //添加约束
        forwordBtn.snp_makeConstraints { (make) -> Void in
            make.leading.bottom.top.equalTo(self)
            make.width.equalTo(self).multipliedBy(1/3.0)
        }
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(forwordBtn.snp_trailing)
            make.top.bottom.equalTo(self)
            make.width.equalTo(forwordBtn)
        }
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentBtn.snp_trailing)
            make.top.bottom.equalTo(self)
            make.width.equalTo(forwordBtn)
        }
        lineOne.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(forwordBtn)
            make.centerY.equalTo(self)
        }
        lineTwo.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(commentBtn)
            make.centerY.equalTo(self)
        }
        
    }
    
    //MARK - 懒加载控件
    //1.转发按钮
    private lazy var forwordBtn:UIButton = UIButton(imageName: "timeline_icon_retweet", bgImageName: "timeline_card_middle_background", title: "转发", sizeFont: HDBottomFontSize)
    
    //2.评论按钮
    private lazy var commentBtn: UIButton = UIButton(imageName: "timeline_icon_comment", bgImageName: "timeline_card_middle_background", title: "评论", sizeFont:HDBottomFontSize)
    //3.点赞按钮
    private lazy var likeBtn: UIButton = UIButton(imageName: "timeline_icon_like", bgImageName: "timeline_card_middle_background", title: "赞", sizeFont: HDBottomFontSize)
    //4.分割线1
    private lazy var lineOne:UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))
    //5.分割线2
    private lazy var lineTwo:UIImageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line_highlighted"))

}
extension UIButton{
    
    convenience init(imageName:String , bgImageName:String , title:String ,sizeFont:CGFloat)  {
        self.init()
        //设置前景
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        
        //设置背景
        setBackgroundImage(UIImage(named: bgImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: bgImageName+"_highlighted"), forState: UIControlState.Highlighted)
        
        //设置字体
        titleLabel?.font = UIFont.systemFontOfSize(sizeFont)
        
        setTitleColor(UIColor.lightGrayColor(), forState: UIControlState.Normal)
        
        //设置文本内容
        setTitle(title, forState: UIControlState.Normal)
        
    }
}

